{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "4cf4eec7-a84c-4476-861e-2b331ee1fc1b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os, pickle\n",
    "def load_filenames(data_dir, split):\n",
    "    filepath = 'filenames_%s.pickle'%split\n",
    "    if os.path.isfile(filepath):\n",
    "        with open(filepath, 'rb') as f:\n",
    "            filenames = pickle.load(f)\n",
    "        print('load filenames from %s'%filepath)\n",
    "    else:\n",
    "        filenames = []\n",
    "    return filenames"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5bef660a-3759-4c04-ac48-4294d22e66ef",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "load filenames from filenames_test.pickle\n",
      "load filenames from filenames_train.pickle\n"
     ]
    }
   ],
   "source": [
    "test_names = load_filenames('./', 'test')\n",
    "train_names = load_filenames('./', 'train')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "59d53158-ea02-452e-9774-03771ca1f2e3",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 6000/6000 [15:54<00:00,  6.29it/s]\n"
     ]
    }
   ],
   "source": [
    "from tqdm import tqdm\n",
    "for i in tqdm(range(len(test_names))):\n",
    "    file_name = test_names[i]\n",
    "    try:\n",
    "        os.system(f'cp ./CelebA-HQ-img/{file_name}.jpg ./test/{file_name}.jpg')\n",
    "        os.system(f'cp ./CelebA-HQ-img/{file_name}.txt ./test/{file_name}.txt')\n",
    "    except:\n",
    "        raise(f'{file_name} not found')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "94a47478-d0d7-4b4b-9ac7-6f35c6b52291",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 24000/24000 [1:08:18<00:00,  5.86it/s]\n"
     ]
    }
   ],
   "source": [
    "for i in tqdm(range(len(train_names))):\n",
    "    file_name = train_names[i]\n",
    "    try:\n",
    "        os.system(f'cp ./CelebA-HQ-img/{file_name}.jpg ./train/{file_name}.jpg')\n",
    "        os.system(f'cp ./CelebA-HQ-img/{file_name}.txt ./train/{file_name}.txt')\n",
    "    except:\n",
    "        raise(f'{file_name} not found')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e21c30d8-bfe2-4497-9bf7-2d0e0a94a615",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
